package net.borderwars.vm;

import java.util.HashMap;
import java.util.Stack;

/**
 * @author ehubbard
 *         Date: May 16, 2006
 *         Time: 11:28:24 AM
 */
public class VMState {

    static public enum STATUS {NORMAL,EXITED}

    STATUS status = STATUS.NORMAL;

    public void markAsDone() {
        status = STATUS.EXITED;
    }
    public STATUS getStatus() {
        return(status);
    }

    public boolean isDone() {
        return(status == STATUS.EXITED);
    }

    // this has bytecode and source for the current method
    MethodStruct currentMethod;
    // current stack
    Stack stack;
    // all the class local variables
    HashMap<String, Number> fields = new HashMap<String, Number>();
    // current PC
    int currentPC;

    public MethodStruct getCurrentMethod() {
        return currentMethod;
    }

    public Stack getStack() {
        return stack;
    }

    

    public int getPC() {
        return currentPC;
    }



    public void setCurrentMethod(MethodStruct currentMethod) {
        this.currentMethod = currentMethod;
    }

    public void setStack(Stack stack) {
        this.stack = stack;
    }



    public Object getField(String name) {
        return(fields.get(name));
    }

    public void setField(String name, Number o) {
        fields.put(name, o);
    }

    public void setPC(int currentPC) {
        this.currentPC = currentPC;
    }

    public final MethodStruct endmarker = new MethodStruct(null, "End Program");
    public VMState() {
        this.currentMethod = endmarker;
        this.stack = new Stack();
        this.fields = new HashMap<String, Number>();
        this.currentPC = 0;
    }
}
